﻿using System;
using System.IO;
using System.Web.UI;
using DFT.DB;

namespace DFT.AJAX
{
    public partial class GetImage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Byte[] imageByte = new Byte[0];
            String imageType = "";
            if (DBManager.GetImage(Int64.Parse(Request.QueryString["profId"]), ref imageByte, ref imageType))
            {
                if (!String.IsNullOrEmpty(imageType) && imageByte.Length > 0)
                {
                    Response.ContentType = imageType;
                    Response.OutputStream.Write(imageByte, 0, imageByte.Length);
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    String imagePath = "~/images/male.gif";
                    if (Request.QueryString["g"] == "f")
                    {
                        imagePath = "~/images/female.gif";
                    }
                    FileStream streamObj = File.OpenRead(Page.MapPath(imagePath));
                    imageByte = new Byte[streamObj.Length];
                    streamObj.Read(imageByte, 0, imageByte.Length);
                    Response.ContentType = "image/gif";
                    Response.OutputStream.Write(imageByte, 0, imageByte.Length);
                    Response.Flush();
                    Response.End();
                }
            }
        }
    }
}